package com.hz.ruoyiseller.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hz.rouyigonggong.domain.LgInboundOrder;
import com.hz.rouyigonggong.domain.LgSeller;
import com.hz.rouyigonggong.domain.LgSellerInfo;
import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.hz.ruoyiseller.dto.LgSellerInfoDTO;
import com.hz.ruoyiseller.dto.LgSellerOutInfoDTO;
import com.hz.ruoyiseller.queryentity.LgSellerInfoQueryEntity;
import com.hz.ruoyiseller.service.LgSellerInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 卖家仓储信息Controller
 *
 * @author grx
 * @date 2025-03-07
 */
@RestController
@Slf4j
@RequestMapping("/info")
public class LgSellerInfoController extends BaseController {
    @Autowired
    private LgSellerInfoService lgSellerInfoService;

    /**
     * 查询卖家列表
     */
    @RequiresPermissions("seller:info:list")
    @GetMapping("/list")
    public TableDataInfo list(LgSellerInfoQueryEntity lgSellerInfoQueryEntity) {
        startPage();
//        lgSellerInfoQueryEntity.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        List<LgSellerInfoDTO> list = lgSellerInfoService.getList(lgSellerInfoQueryEntity);
        System.out.println(list);
          return getDataTable(list);
        }


    /**
     * 导出卖家列表
     */
    @RequiresPermissions("seller:info:export")
    @Log(title = "卖家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LgSeller lgSeller)
    {
//        //List<LgSeller> list = lgSellerService.selectLgSellerList(lgSeller);
//        List<LgSeller> list = lgSellerService.list(null);
//        ExcelUtil<LgSeller> util = new ExcelUtil<LgSeller>(LgSeller.class);
//        util.exportExcel(response, list, "卖家数据");
    }

    /**
     * 获取卖家详细信息
     */
    @RequiresPermissions("seller:info:query")
    @GetMapping(value = "/{sellerInfoId}")
    public TableDataInfo getInfo(@PathVariable("sellerInfoId") String sellerInfoId)
    {
        startPage();
        LgInboundOrder sellerIdAndGoodsId = lgSellerInfoService.getSellerIdAndGoodsId(Integer.parseInt(sellerInfoId));
        System.out.println(sellerIdAndGoodsId);
        List<LgSellerOutInfoDTO> outList = lgSellerInfoService.getOutList(sellerIdAndGoodsId.getSellerId(), sellerIdAndGoodsId.getGoodsId());
        return getDataTable(outList);
    }

    /**
     * 新增卖家仓储
     */
    @RequiresPermissions("seller:info:add")
    @Log(title = "卖家仓储", businessType = BusinessType.INSERT)
    @PostMapping
    public void add(@RequestBody LgSellerInfo lgSellerInfo)
    {
    lgSellerInfoService.save(lgSellerInfo);
    }

    /**
     * 修改卖家
     */
    @RequiresPermissions("seller:info:edit")
    @Log(title = "卖家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LgSeller lgSeller)
    {
//        return toAjax(lgSellerService.updateLgSeller(lgSeller));
//        return toAjax(lgSellerService.updateById(lgSeller));
        return toAjax(1);
    }

    /**
     * 删除卖家
     */
    @RequiresPermissions("seller:info:remove")
    @Log(title = "卖家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sellerIds}")
    public AjaxResult remove(@PathVariable String[] sellerIds)
    {
//        return toAjax(lgSellerService.deleteLgSellerBySellerIds(sellerIds));
        return toAjax(1);
    }
}
